#lang racket


(require "../base/main.rkt")

(require "ac-com.rkt")

(provide arc-ppp-command
         cone-frustrum-command
         entlast-command
         join-command
         loft-command
         redo
         regen
         sweep
         undo)


; lisp

(define (cone-frustrum-lisp p base-radius top-radius height)
  (string-append
   "._cone "
   (format "~A,~A,~A " (vector-ref p 0) (vector-ref p 1) (vector-ref p 2))
   (format "~A _T ~A ~A " base-radius top-radius height)))

(define (handent-lisp handle)
  (string-append "(handent \"" handle "\")"))

(define (join-lisp objects)
  (apply
   string-append
   "._join "
   (map
    (λ (entity)
      (format "~A " (handent-lisp (get-handle entity))))
    objects)))


; commands

(define (arc-ppp-command p1 p2 p3)
  (send-command
   (string-append
    "._arc "
    (format "~A,~A,~A " (vector-ref p1 0) (vector-ref p1 1) (vector-ref p1 2))
    (format "~A,~A " (vector-ref p2 0) (vector-ref p2 1))
    (format "~A,~A " (vector-ref p3 0) (vector-ref p3 1))))
  (entlast-command))

(define (cone-frustrum-command p base-radius top-radius height)
  (send-command
   (cone-frustrum-lisp p base-radius top-radius height))
  (entlast-command))

(define (entlast-command)
  (item (- (get-modelspace-count) 1)))

(define (join-command objects)
  (send-command
   (format "~A " (join-lisp objects)))
  (entlast-command))

(define (loft-command objects)
  (send-command
   (string-append
    "._loft "
    (apply
     string-append
     (map
      (λ (object)
        (string-append (handent-lisp (get-handle object)) " "))
      objects))
    vbCr))
  (entlast-command))

(define (redo)
  (send-command (string-append "redo" vbCr)))

(define (regen)
  (send-command (string-append "regen" vbCr)))

(define (sweep object path)
  (send-command
   (string-append
    "sweep "
    (handent-lisp (get-handle object))
    vbCr
    (handent-lisp (get-handle path))
    " ")))

(define (undo)
  (send-command (string-append "undo" vbCr)))